﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using AB.ServiceDirectory.Entities;
using NUnit.Framework;
namespace AB.ServiceDirectory.TestScripts
{
    [TestFixture]
    public class HOrganizationTestBO
    {
        //This is for comparing two objects type of Organization
        private class  OrgisationComparer:IEqualityComparer<Organization>
        {
            /// <summary>
            /// Determines whether the specified objects are equal.
            /// </summary>
            /// <param name="x">The first object of type <paramref name="T"/> to compare.</param>
            /// <param name="y">The second object of type <paramref name="T"/> to compare.</param>
            /// <returns>
            /// true if the specified objects are equal; otherwise, false.
            /// </returns>
            public bool Equals(Organization x, Organization y)
            {
                return (x.OrganizationId == y.OrganizationId) && (x.OrganizationName == y.OrganizationName) &&
                       (x.ShortDescription == y.ShortDescription) && (x.AddressId == y.AddressId) &&
                       (x.BusinessId == y.BusinessId) && (x.PhoneNumber == y.PhoneNumber) &&
                       (x.CityTown == y.CityTown) && (x.County == y.County) &&
                       (x.CountryId==y.CountryId)&&
                       (x.PreferredOrganization == y.PreferredOrganization) && (x.FullDescription == y.FullDescription) &&
                       (x.ContactId == y.ContactId) && (x.Fax == y.Fax) &&
                       (x.Email == y.Email) && (x.WebAddress == y.WebAddress) &&
                       (x.CharityNumber == y.CharityNumber) && (x.CompanyNumber == y.CompanyNumber) &&
                       (x.OrganizationSpecialism == y.OrganizationSpecialism) &&
                       (x.ServiceDisabilities == y.ServiceDisabilities) && (x.ServiceBarriers == y.ServiceBarriers) &&
                       (x.ServiceBenefits == y.ServiceBenefits) && (x.ServiceCircumstances == y.ServiceCircumstances) &&
                       (x.ServiceEthnicity == y.ServiceEthnicity) && (x.Accreditation == y.Accreditation) &&
                       (x.IsActive == y.IsActive);
            }

            public int GetHashCode(Organization obj)
            {
                throw new NotImplementedException();
            }

        }

        private string _sortType;
        private int _startRowIndex;
        private int _maxRows;

        /// <summary>
        /// Creates the sample Organization.
        /// </summary>
        /// <returns></returns>
        public Organization CreateSampleOrganization()
        {
            var Organization = new Organization
            {
                OrganizationId = 12,
                OrganizationName = "Gavin922",
                ShortDescription =
                    "cognitio, habitatio plorum transit. rarendum manifestum gravis bono Quad non vobis Versus esset si et delerium. Id ut",
                AddressId = 47,
                BusinessId = 88,
                PhoneNumber = "141-2236180",
                CityTown = "Baltimore",
                County = "Vermont",
                CountryId = "Turkey",
                PreferredOrganization = false,
                FullDescription =
                    "quad in trepicandor et eudis si estis quantare bono et quantare plorum delerium. quad non vobis quoque si",
                ContactId = 10,
                Fax = "984-8156622",
                Email = "nlzcxd.xykfiio@hikdbtkmy.ywzxgf.org",
                WebAddress = "http://lllip.webc58/acwoa/umcrs/erkwe/dxujh.php",
                CharityNumber = "29624",
                CompanyNumber = "25088",
                OrganizationSpecialism = null,
                ServiceDisabilities = null,
                ServiceBarriers = null,
                ServiceBenefits = null,
                ServiceCircumstances = null,
                ServiceEthnicity = null,
                Accreditation = null,
                IsActive = false,
            };
            return Organization;
        }

        /// <summary>
        /// Setups this instance.
        /// </summary>
        [SetUp]
        public void Setup()
        {
            _sortType = "OrganizationName";  //sortExpression="Organization"
            _startRowIndex = 0;  //from rowindex=0
            _maxRows = 15;  //take 15 records
        }

        #region GetOrganizationById

        /// <summary>
        /// Tests the get Organization by id_ input exist Organization id_ return an Organization.
        /// </summary>
        [Test]
        public void TestGetOrganizationById_InputExistOrganizationId_ReturnAnOrganization()
        {
            var expectedOrganization = CreateSampleOrganization();
            var actualOrganization = BO.HOrganizationBO.GetOrganizationById(12);
            Assert.IsTrue(new OrgisationComparer().Equals(expectedOrganization,actualOrganization));
        }

        /// <summary>
        /// Tests the get Organization by id_ input not exist Organization id_ return null.
        /// </summary>
        [Test]
        public void TestGetOrganizationById_InputNotExistOrganizationId_ReturnNull()
        {
            int OrganizationId = 000;
            Assert.IsNull(BO.HOrganizationBO.GetOrganizationById(OrganizationId));
        }

        #endregion

        #region GetOrganizationCount

        [Test]
        public void TestGetOrganizationCount_InputFilter1_ReturnContactRowCount()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(new Collection<string>(){"a","b","c","d","e"});
            filter.IncludeInactive = true;
            int rowCount = BO.HOrganizationBO.GetOrganizationCount(filter);
            Assert.Greater(rowCount,0);
        }

        [Test]
        public void TestGetOrganizationCount_InputFilter2_ReturnContactRowCount()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(new Collection<string>() { "a", "b", "c", "d", "e" });
            filter.IncludeInactive = false;
            int rowCount = BO.HOrganizationBO.GetOrganizationCount(filter);
            Assert.Greater(rowCount, 0);
        }

        [Test]
        public void TestGetOrganizationCount_InputFilter3_ReturnContactRowCount()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(null);
            filter.IncludeInactive = true;
            int rowCount = BO.HOrganizationBO.GetOrganizationCount(filter);
            Assert.Greater(rowCount, 0);
        }

        [Test]
        public void TestGetOrganizationCount_InputFilter4_ReturnContactRowCount()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(null);
            filter.IncludeInactive = false;
            int rowCount = BO.HOrganizationBO.GetOrganizationCount(filter);
            Assert.Greater(rowCount, 0);
        }


        #endregion

        #region GetOrganization

        [Test]
        public void TestGetOrganization_InputFilter1_ReturnListOrganization()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(new Collection<string>() { "a", "b", "c", "d", "e" });
            filter.IncludeInactive = true;
            int numOrganization = BO.HOrganizationBO.GetOrganization(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(numOrganization, 0);
        }

        [Test]
        public void TestGetOrganization_InputFilter2_ReturnListOrganization()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(new Collection<string>() { "a", "b", "c", "d", "e" });
            filter.IncludeInactive = false;
            int numOrganization = BO.HOrganizationBO.GetOrganization(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(numOrganization, 0);
        }

        [Test]
        public void TestGetOrganization_InputFilter3_ReturnListOrganization()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(null);
            filter.IncludeInactive = true;
            int numOrganization = BO.HOrganizationBO.GetOrganization(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(numOrganization, 0);
        }

        [Test]
        public void TestGetOrganization_InputFilter4_ReturnListOrganization()
        {
            var filter = new Commons.DataFilters.HOrganizationFilter();
            filter.SetBeginningLetters(null);
            filter.IncludeInactive = false;
            int numOrganization = BO.HOrganizationBO.GetOrganization(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(numOrganization, 0);
        }
        #endregion
    }
}
